<template>
  <tr>
    <td>
      <input v-model="goodList.checked" type="checkbox" name="" id="" />
    </td>
    <td>{{ goodList.name }}</td>
    <td>{{ goodList.price }}</td>
    <td>
      <button @click="prevFn">-</button>
      &nbsp;{{ goodList.num }}&nbsp;
      <button @click="addFn">+</button>
    </td>
    <td>{{ sum }}</td>
    <td><button @click="del(goodList.name)">删除</button></td>
  </tr>
</template>

<script>
export default {
  props: ["goodList"],
  name: "GoshopMytr",

  data() {
    return {
      sum: this.goodList.price,
    };
  },
  watch: {
    goodList: {
      deep: true,
      handler(vle) {
        this.sum = vle.price * vle.num;
      },
    },
  },
  mounted() {},

  methods: {
    prevFn() {
      if (this.goodList.num <= 1) {
        return (this.goodList.num = 1);
      }
      return this.goodList.num--;
    },
    addFn() {
      return this.goodList.num++;
    },
    del() {
      this.$emit("delFn", this.goodList.name);
    },
  },
};
</script>